import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const NavigatorLang = (navigator.language || navigator.userLanguage).substr(0, 2);
const state={
    currentLang: localStorage.getItem('UserLang') || 'cn',
    itemlist:[{
        icon: 'el-icon-setting',
        index: 'dashboard',
        title: localStorage.getItem('UserLang')=='en'?'System Home Page':'系统首页'
    },
    {
        icon: 'el-icon-tickets',
        index: 'table',
        title: localStorage.getItem('UserLang')=='en'?'Basic table':'基础表格'
    },
    {
        icon: 'el-icon-message',
        index: 'tabs',
        title: localStorage.getItem('UserLang')=='en'?'Tab tab':'tab选项卡'
    },
    {
        icon: 'el-icon-date',
        index: '3',
        title: localStorage.getItem('UserLang')=='en'?'Form correlation':'表单相关',
        subs: [
            {
                index: 'form',
                title: localStorage.getItem('UserLang')=='en'?'Basic form':'基本表单'
            },
            {
                index: 'editor',
                title: localStorage.getItem('UserLang')=='en'?'Rich Text Editor':'富文本编辑器'
            },
            {
                index: 'markdown',
                title: localStorage.getItem('UserLang')=='en'?'markdown editor':'markdown编辑器'
            },
            {
                index: 'upload',
                title: localStorage.getItem('UserLang')=='en'?'File upload':'文件上传'
            }
        ]
    },
    {
        icon: 'el-icon-star-on',
        index: 'charts',
        title: localStorage.getItem('UserLang')=='en'?'schart Chart ':'echart图表'
    },
    {
        icon: 'el-icon-rank',
        index: 'drag',
        title: localStorage.getItem('UserLang')=='en'?'Drag-and-drop list':'拖拽列表'
    },
    {
        icon: 'el-icon-warning',
        index: 'permission',
        title: localStorage.getItem('UserLang')=='en'?'Privilege testing':'权限测试'
    },
    {
        icon: 'el-icon-error',
        index: '404',
        title: localStorage.getItem('UserLang')=='en'?'404 pages':'404页面'
    }]
  };
const mutations ={
    updateLang(state, value) {
        state.currentLang = value;
        state.itemlist = [
            {
                icon: 'el-icon-setting',
                index: 'dashboard',
                title: value=='en'?'System Home Page':'系统首页'
            },
            {
                icon: 'el-icon-tickets',
                index: 'table',
                title: value=='en'?'Basic table':'基础表格'
            },
            {
                icon: 'el-icon-message',
                index: 'tabs',
                title: value=='en'?'Tab tab':'tab选项卡'
            },
            {
                icon: 'el-icon-date',
                index: '3',
                title: value=='en'?'Form correlation':'表单相关',
                subs: [
                    {
                        index: 'form',
                        title: value=='en'?'Basic form':'基本表单'
                    },
                    {
                        index: 'editor',
                        title: value=='en'?'Rich Text Editor':'富文本编辑器'
                    },
                    {
                        index: 'markdown',
                        title: value=='en'?'markdown editor':'markdown编辑器'
                    },
                    {
                        index: 'upload',
                        title: value=='en'?'File upload':'文件上传'
                    }
                ]
            },
            {
                icon: 'el-icon-star-on',
                index: 'charts',
                title: value=='en'?'schart Chart ':'echart图表'
            },
            {
                icon: 'el-icon-rank',
                index: 'drag',
                title: value=='en'?'Drag-and-drop list':'拖拽列表'
            },
            {
                icon: 'el-icon-warning',
                index: 'permission',
                title: value=='en'?'Privilege testing':'权限测试'
            },
            {
                icon: 'el-icon-error',
                index: '404',
                title: value=='en'?'404 pages':'404页面'
            }
        ]
        localStorage.setItem('UserLang', state.currentLang)
      }
}

 
const store = new Vuex.Store({
    state,
    mutations,
 });

export default store;